package cn.com.shopec.erp.stock.commo;

import cn.com.shopec.erp.common.constant.SZSCMConstant;
import cn.com.shopec.erp.common.utils.DateUtil;
import cn.com.shopec.erp.product.entity.ProductStock;
import cn.com.shopec.erp.stock.entity.StockHistory;
import cn.com.shopec.erp.stock.entity.StockOut;
import cn.com.shopec.erp.stock.entity.StockOutProduct;
import cn.com.shopec.erp.stock.vo.StockHistoryVo;
import cn.com.shopec.erp.stock.vo.StockInProductVo;
import cn.com.shopec.erp.stock.vo.StockInVo;

public class StockHistroyUtil{

	public static StockHistoryVo parseStockHistory(StockHistory stockHistory) {
		if (stockHistory == null) {
			return null;
		}
		StockHistoryVo stockHistoryVo = new StockHistoryVo();
		stockHistoryVo.setId(stockHistory.getId());
		stockHistoryVo.setStockNo(stockHistory.getStockNo());
		stockHistoryVo.setChangeQuantity(stockHistory.getChangeQuantity());
		stockHistoryVo.setStockType(stockHistory.getStockType());
		stockHistoryVo.setCreateTime(stockHistory.getCreateTime());
		stockHistoryVo.setOriginalQuantity(stockHistory.getOriginalQuantity());
		stockHistoryVo.setCommoNo(stockHistory.getCommoNo());
		stockHistoryVo.setWhNo(stockHistory.getWhNo());
		stockHistoryVo.setProdNo(stockHistory.getProdNo());
		stockHistoryVo.setStockTypeNo(stockHistory.getStockTypeNo());
		stockHistoryVo.setSupNo(stockHistory.getSupNo());
		return stockHistoryVo;
	}

	public static StockHistory parseStockHistory(StockInVo stockIn, StockInProductVo stockInProduct,
			ProductStock productStock) {
		StockHistory stockHistory = new StockHistory();
		stockHistory.setStockNo(stockIn.getStockInNo());
		stockHistory.setCreater(stockIn.getUpdater());
		stockHistory.setCreateTime(DateUtil.getCurrentDate());
		stockHistory.setStockType(stockIn.getStockInType());
		stockHistory.setPurNo(stockIn.getPurNo());
		stockHistory.setStockTypeNo(stockIn.getStockInTypeNo());
		stockHistory.setWhNo(productStock.getWhNo());
		stockHistory.setProdNo(productStock.getProdNo());
		stockHistory.setSupNo(productStock.getSupNo());
		stockHistory.setCommoNo(productStock.getCommoNo());
		stockHistory.setChangeQuantity(stockInProduct.getQualifiedQuantity() + stockInProduct.getDefectiveQuantity());
		stockHistory.setOriginalQuantity(productStock.getProductTotal() - stockHistory.getChangeQuantity());
		stockHistory.setDeletedFlag(SZSCMConstant.DELETE_FLAG_NO);
		return stockHistory;
	}

	public static StockHistory parseStockHistory(StockOut stockOut, StockOutProduct stockOutProduct,long nowProductTotal) {
		StockHistory stockHistory = new StockHistory();
		stockHistory.setStockNo(stockOut.getStockOutNo());
		stockHistory.setCreater(stockOut.getCreater());
		stockHistory.setCreateTime(DateUtil.parseSqlDate(DateUtil.getCurrentDate()));
		stockHistory.setPurNo(stockOutProduct.getPurNo());
		stockHistory.setStockType(stockOut.getStockOutType());
		stockHistory.setWhNo(stockOutProduct.getWhNo());
		stockHistory.setProdNo(stockOutProduct.getProdNo());
		stockHistory.setSupNo(stockOutProduct.getSupNo());
		stockHistory.setCommoNo(stockOutProduct.getCommoNo());
		stockHistory.setChangeQuantity(stockOutProduct.getStockoutQuantity());
		stockHistory.setOriginalQuantity(nowProductTotal + stockHistory.getChangeQuantity());
		stockHistory.setDeletedFlag(SZSCMConstant.DELETE_FLAG_NO);
		return stockHistory;
	}
	
}
